<template>
  <div>
    <crumbs secondTitle="数据统计" thirdTitle="数据报表"></crumbs>

    <!-- 卡片视图 -->
    <el-card>
      <!-- 2.为 Echarts 准备一个盒子 -->
      <div id="main" style="width:750px;height:400px;"></div>
    </el-card>
  </div>
</template>

<script>
// 1.导入 eacharts 图表
import echarts from 'echarts'
import { getIcon } from '@/api/report'
import _ from 'lodash'
export default {
  data() {
    return {
      // 需要跟请求的折线图数据合并的options
      options: {
        title: {
          text: '用户来源'
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross',
            label: {
              backgroundColor: '#E9EEF3'
            }
          }
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: [
          {
            boundaryGap: false
          }
        ],
        yAxis: [
          {
            type: 'value'
          }
        ]
      }
    }
  },
  async mounted() {
    const res = await getIcon()
    if (res.meta.status !== 200) {
      return this.$message.error('获取图标失败')
    }
    // 3.基于准备好的dom，初始化echarts实例
    var myChart = echarts.init(document.getElementById('main'))
    // 4. 准备数据和配置项
    const result = _.merge(res.data, this.options)
    // 5.展示数据
    myChart.setOption(result)
  }
}
</script>

<style lang="less" scoped></style>
